<template>
    房号名称:
    <input type="text" v-model="names" placeholder="请输入房号名称">
    创建时间:
    <input type="date" v-model="date">
    <input type="button" value="查询" @click="shows"> 

    <input type="button" value="导入" @click="daoru"> 

    <input type="button" value="导出" @click="daochu"> 

   <table border="1">
    <thead>
    <tr>
        <td>房号id</td>
        <td>房号</td>
        <td>房号状态</td>
        <td>备注</td>
        <td>创建时间</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
        <tr v-for="i in show">
        <td>{{ i.RN_Id }}</td>
        <td>{{ i.RN_Num }}</td>
        <td>{{ i.RN_Status?"上架":"下架" }}</td>
        <td>{{ i.RN_BeiZhu }}</td>
        <td>{{ i.RN_DateTime.substring(0,10) }}</td>
        <td>
            <input type="button" value="修改" @click="xiugai(i.RN_Id)">
            <input type="button" value="下架" @click="xiajia(i.RN_Id)">
        </td>
    </tr>
    </tbody>
  
   </table>
</template>

<script setup lang="ts">
import {onMounted,ref} from 'vue'
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios'
import {useCounterStore} from '../../stores/counter.ts'

const userstore=useCounterStore();

const user=useRouter();
const use=useRoute();

const names=ref("")
const date=ref("")
onMounted(()=>{
    shows();
})
//显示字段
const show=ref([
  {
    "RN_Id": 1,
    "RN_Num": "1002",
    "RN_Status": true,
    "RN_BeiZhu": "安静",
    "RN_DateTime": "0001-01-01T00:00:00"
  }
])
//显示
const shows=()=>{
    axios.get("https://localhost:7234/api/RoomNumber/GetNumberAll",{
        params:{
            name:names.value,
            time:date.value
        }
    })
    .then(res=>{
        show.value=res.data
    })
}
//下架
const xiajia=(RN_Id:number)=>{
    if(confirm("您确定要下架吗?")){
  axios.put("https://localhost:7234/api/RoomNumber/Upda?id="+RN_Id)
    .then(res=>{
        if(res.data>0){
            alert("执行成功");
            shows();
        }else if(res.data==-1){
            alert("已下架")
        }
    })
}
    }
  
//修改
const xiugai=(RN_Id:number)=>{
    user.push({
        name:"UpdaNumber",
        params:{
        id:RN_Id
        }
    })
}
//导入
const daoru=()=>{
axios.post("https://localhost:7234/api/RoomNumber/DaoRu?Fpth="+"D:\\专高二\\yk.xlsx")
.then(res=>{
    if(res.data>0){
        alert("导入成功");  shows();
    }else{
        alert("导入失败")
    }
})
}
//导出
const daochu=()=>{
axios.post("https://localhost:7234/api/RoomNumber/Daochu?Fpth="+"D:\\专高二\\yk.xlsx")
.then(res=>{
    if(res.data>0){
        alert("导出成功");
        shows();
    }else{
        alert("导出失败")
    }
})
}



</script>

<style scoped>

</style>